package com.insurance.web;

import java.util.List;

import javax.annotation.Resource;
import com.insurance.bean.Company;
import com.insurance.service.CompanyService;


public class CompanyAction {
	@Resource CompanyService companyService;
	private String message;
	private List<Company> companys;
	private Company company;
	private Integer id;
	
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public Company getCompany() {
		return company;
	}
	public void setCompany(Company company) {
		this.company = company;
	}
	/**
	 * show all companys
	 */
	public String list(){
		this.companys = companyService.getCompanys();
		return "list";
	}
	/**
	 * add a company UI
	 */
	public String addUI(){
		return "add";
	}
	
	/**
	 * add a company
	 */
	public String add(){
		if(this.company == null)
			return "fail";
		else{
		this.companyService.save(this.company);
		this.message="add a company success";
		return "message";
		}
	}
	
	/**
	 * 
	 * modify company information UI
	 */
	public String modifyCompany(){
		this.company = this.companyService.getCompany(this.id);
		return "modify";
	}
	
	/**
	 * 
	 * modify company information
	 */
	public String modify(){
		this.companyService.update(this.company);
		this.message="modify success";
		return "message";
	}
	/**
	 * 	
	 * delete a company
	 */
	public String del(){			
			this.companyService.delete(this.id);
			this.message="delete success";
			return "message";
	}
	
	public List<Company> getCompanys() {
		return companys;
	}

	public void setCompanys(List<Company> companys) {
		this.companys = companys;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
}
